package com.lh_travel.lohas.dialogFragment;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;

import com.lh_travel.lohas.R;

@SuppressLint("ValidFragment")
public class progressDialogFragment extends DialogFragment {

    private Context context;

    public progressDialogFragment() {
    }

    public progressDialogFragment(Context context) {
        this.context = context;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {

        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
       // getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);

        View v = inflater.inflate(R.layout.progress, null);
        v.setBackgroundColor(Color.TRANSPARENT);

        return v;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //点击fragment外面不消失
        this.setCancelable(false);

    }

    @Override
    public void onStart() {
        super.onStart();

        Window window = getDialog().getWindow();
        WindowManager.LayoutParams windowParams = window.getAttributes();
        windowParams.dimAmount = 0.0f;

        window.setAttributes(windowParams);
    }

    public void dismiss(boolean isResume){
        if(isResume){
            dismiss();
        }else{
            dismissAllowingStateLoss();
        }
    }

    /**
     * 判断弹窗是否显示
     * @return
     */
    public boolean isShowing(){
        return getDialog() != null && getDialog().isShowing();
    }

    @Override
    public void dismiss() {
        if(isShowing()){
            super.dismiss();
        }
    }

    @Override
    public void dismissAllowingStateLoss() {
        if(isShowing()){
            super.dismissAllowingStateLoss();
        }
    }
}
